<?php
namespace App\Http\Controllers\Home;

use App\Models\Group;

Class GroupController extends BaseController{

    public function __construct(Group $group)
    {
         parent::__construct();
         $this->group = $group;
    }

    //团队管理
    public function getIndex(){
        $group_info = $this->group->getGroupInfo();
        return view('home.tg.index',compact('group_info'));
    }

    //团队列表
    public function getGroupList(){
        $res = $this->group->groupList();
        return view('home.tg.list_group',compact('res'));
    }

    // 加入团队
    public function getJoin(){
        return view('home.tg.join');
    }

    public function postJoin(){
       $res = $this->group->joinGroup(request());
        if($res['state']!=200) {
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }
        return redirect('/group/my-join');
    }

    /**
     * 我加入的团队
     * @return
     */
    public function getMyJoin(){
         $res = $this->group->myJoinGroup();
         return view('home.tg.myteam',compact('res'));
    }

    //创建团队
    public function getCreteGroup(){
         return view('home.tg.group_add');
    }

    public function postCreteGroup(){
        $res = $this->group->createGroup(request());
        if($res['state']!=200) {
            return redirect()->back()->with('message', $res['msg'])->withInput();
        }
        return redirect('/group/group-list');
    }
}